
import java.util.Timer;
import javax.microedition.lcdui.game.Sprite;

/**
 *
 * @author pdb
 */
public class QuestionBlock {
    //Voor de question block
    private Sprite questionblock;
    private int QBDelay = 150;
    private int[] QBAnimationSequence = {0, 1, 2};
    private SpriteAnimationTask sprQB;
    private Timer timer1;    //Sound player
    private boolean Hit = false;
    private boolean HitAnimationReady = false;
    private Coin HitCoin;

    public QuestionBlock() {
        //Laad de plaatjes
        LoadGraphics grCoin = new LoadGraphics();
        this.questionblock = grCoin.getSprite_QuestionBlock(QBAnimationSequence);
        this.sprQB = new SpriteAnimationTask(getQuestionBlock(), true);
        this.sprQB.setMoving(true);
        this.timer1 = new Timer();
        this.timer1.scheduleAtFixedRate(sprQB, 0, QBDelay);
    }

    public void UpdateCoin() {
        this.questionblock.nextFrame();
    }

    public Sprite getQuestionBlock() {
        return questionblock;
    }

    public void setQuestionBlock(Sprite QuestionBlock) {
        this.questionblock = QuestionBlock;
    }

    /**
     * Checks for collision with the player character. If found, shows the coin
     * and plays the sound
     */
    public boolean CheckForCollision(Sprite mario) {
        if (this.questionblock.collidesWith(mario, false)) {
            //Check if Mario is hitting from below
            if (mario.getY() > this.questionblock.getY()) {
                //make not visible
                this.questionblock.setVisible(false);
                //Play sound
                //Indicate hit, and coin animation
                Hit = true;
                this.HitCoin = new Coin();
                this.HitCoin.getCoin().setPosition(this.questionblock.getX(), this.questionblock.getY());
            }
        }
        
        return Hit;
    }

    public boolean UpdateCoinAnimation() {
        this.HitAnimationReady = this.HitCoin.MoveCoin();
        return this.HitAnimationReady;
    }

    public boolean isHit() {
        return Hit;
    }

    public void setHit(boolean Hit) {
        this.Hit = Hit;
    }

    public boolean isHitAnimationReady() {
        return HitAnimationReady;
    }

    public void setHitAnimationReady(boolean HitAnimationReady) {
        this.HitAnimationReady = HitAnimationReady;
    }

    public Coin getHitCoin() {
        return HitCoin;
    }

    public void setHitCoin(Coin HitCoin) {
        this.HitCoin = HitCoin;
    }
}
